package com.zhou.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zhou.constant.MessageConstant;
import com.zhou.entity.Result;
import com.zhou.pojo.Cmedicine;
import com.zhou.pojo.Psychological;
import com.zhou.service.HealthService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/health")
public class HealthController {
    @Reference
    HealthService healthService;
    //心理测评
    @PostMapping("/findAllPsychological")
    public Result findAllPsychological(){
        try {
            List<Psychological>list =healthService.findAllPsychological();
            return new Result(true, MessageConstant.QUERY_PSYCHOLOGICAL_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_PSYCHOLOGICAL_FAIL);
          }
    }
    //心理测评结果
    @RequestMapping("addPsychologicalMemberByPhone")
    public Result addPsychologicalMemberByPhone(@Param("phone")String phone,@Param("answerList")Integer[] answerList){
        try {
            healthService.addPsychologicalMemberByPhone(phone,answerList);
            return new Result(true,MessageConstant.ADD_PSYCHOLOGICALMEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.ADD_PSYCHOLOGICALMEMBER_FAIL);
        }
    }
    //中医体质测评
    @RequestMapping("/findAllCmedicine")
    public Result findAllCmedicine(){
        try {
            List<Cmedicine>list =healthService.findAllCmedicine();
            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
    }
    //中医体质测评结果
    @RequestMapping("addCmedicineMemberByPhone")
    public Result addCmedicineMemberByPhone(@Param("phone")String phone,@Param("answerList")Integer[] answerList){
        try {
            healthService.addCmedicineMemberByPhone(phone,answerList);
            return new Result(true,MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.ADD_CHECKGROUP_FAIL);
        }
    }

}
